function formatar(src, mask){
    var i = src.value.length;
    var saida = mask.substring(0,1);
    var texto = mask.substring(i)
    if (texto.substring(0,1) != saida){
        src.value += texto.substring(0,1);
    }
}

function bg_menu(id){
    document.getElementById(id).style.background = "#66e";
    document.getElementById(id).style.color = "#fff";
}

function add_0(val){
    var p = 0;
    var str = val+'';
    var saida = '';
    
    for(var i = 0; i < str.length; i++){
        if(str.substring(i, i+1) == '.'){
            p = i;
        }
    }
    
    if(p != 0){
        if((p+2) == str.length){
            saida = str+'0';
        }else{
            saida = str;
        }
    }else{
        saida = str+".00";
    }
    
    return saida;
}

function add_p( val ){
    var a = '';
    for(var i = 0; i < val.length; i++){
        if(val.substring(i, i+1) == ','){
            a += '.';
        }else{
            a += val.substring(i, i+1);
        }
    }
    
    return a;
}

function limita_casa( val ){
    var p =0;
    for(i = 0; i < val.length; i++){
        if(val.substring(i, i+1) == '.'){
            p = i;
        }
    }
    if(p > 0){
        return val.substring(0, p+3);
    }else{
        return val;
    }
}

function mostra_tx_palestra( val ){
    if(val == 0){
        document.getElementById("dv_tx_palestra").style.display = "none";
    }else{
        document.getElementById("dv_tx_palestra").style.display = "block";
        var v = document.getElementById("tx_pal_nao").checked;
        if(v == false){
            mostra_tx_inscri(1);
        }
    }
}

function mostra_tx_inscri( val ){
    if(val == 1){
        document.getElementById("dv_tx_inscricao").style.display = "none";
    }else{
        document.getElementById("dv_tx_inscricao").style.display = "block";
    }
}

function selectInst( val, old ){
    if(val === "0"){
        document.getElementById("instituicao").style.display = "block";
        document.getElementById("instituicao").value = old;
    }else{
        document.getElementById("instituicao").style.display = "none";
        document.getElementById("instituicao").value = val;
    }
}

function add_block( tp ){
    var conteiner = document.getElementById("add_block").innerHTML;
    switch(tp){
        case "txInsc":
        conteiner += "\
<div>\n\
    <label>Data de inicial</label>\n\
    <input type='text' value='' name='data[]' OnKeyPress=\"formatar(this, '00/00/0000')\" maxlength='10'>\n\
    <label>Valor da taxa</label>\n\
    <input type='text' value='' name='valor[]'>\n\
</div>";
        break;
        case "info":
        conteiner += "\
<div>\n\
    <label>Data de início da informação</label>\n\
    <input type='text' value='' name='data_inicio[]' OnKeyPress=\"formatar(this, '00/00/0000')\" maxlength='10'>\n\
    <label>Data de vencimento da informação</label>\n\
    <input type='text' value='' name='data_validade[]' OnKeyPress=\"formatar(this, '00/00/0000')\" maxlength='10'>\n\
    <label>Texto da informação</label>\n\
    <textarea name='informacao[]'></textarea>\n\
</div>";
        break;
        default:
        conteiner += "<div><input type='text' value='' name='instituicao[]'></div>";
    }
    document.getElementById("add_block").innerHTML = conteiner;
}
